<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Common as helper;
use Laravel\Lumen\Routing\Controller as BaseController;

class ProductController extends BaseController
{
    function __construct()
    {
        DB::connection()->enableQueryLog(); // 开启查询日志
    }

    public function index(Request $request){
        var_dump($request->get('type'));
        var_dump($request->input('type'));
    }

    // 提取产品列表
    public function lister(){

        $result = DB::select("select * from think_product");
        helper::dump($result);
        echo helper::last_query();
    }
    // 通过id获取产品信息
    public function detail($id){
        echo $id;
        if($id>0){
            $res = DB::table('product')->where("id",$id)->first();
            if(!empty($res)){
                echo json_encode($res);
            }
        }
    }
    public function search(Request $request){
        echo "33";
        helper::dump($request->all()); // 获取所有参数(数组形式)
        $post = $request->all();
        // 使用验证
        if($request->has('email')){
            // 验证email
            $this->validate($request,[
               'email' => 'required|email', // 如果验证不通过，直接返回，不会往下走，不需要手动终止。
            ]);
        }
        echo "44";
    }
}
